﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuanLyNhaHang.Bussiness
{
    class BusOptionLocation
    {
        DataAccess.DAOrder_LocationMst dataOrder;
        GUI.OrderOption.LocationMng f;

        public BusOptionLocation(GUI.OrderOption.LocationMng f2)
        {
            f = f2;
            dataOrder = new DataAccess.DAOrder_LocationMst();
        }

        public void optionLoadLocation()
        {
            this.f.gridControl1.DataSource = dataOrder.optionLoadLocation();
        }

        public Boolean optionNewLocation(String tenKV)
        {
            try
            {
                if (validateLocation(tenKV))   // check duplication location
                {
                    dataOrder.optionNewLocation(tenKV);
                    optionLoadLocation();  //Load Table
                    dataOrder.optionAddFirstTable(tenKV); //Add first table to Location.
                    System.Windows.Forms.MessageBox.Show("Thêm mới thành công!!");
                }
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show("Lỗi xảy ra, vui lòng kiểm tra lại dữ liệu");
                return false;
            }
            return true;
        }

        public void optionDelete(String s)
        {
            //Delete KV - DS_Ban - QL_DatMon
            dataOrder.optionDelete(s);
            //load Table;
            optionLoadLocation();
        }

        public void optionUpdate(String strOld,String strNew){
            // check on function ValidateLocation();
            dataOrder.optionUpdateLocation(strOld, strNew);
            optionLoadLocation();
        }

        public bool validateLocation(String location)
        {
            if (location == "" || dataOrder.optionCheckDupLocation(location) == false)
            {
                MessageBox.Show("Tên khu vực trống hoặc trùng trong cơ sở dữ liệu");
                return false;
            }
            return true;
        }

    }
}
